package gcb.metalsys.utils;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;

import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author ReMidDream
 * @date 2020/7/24 10:34
 **/
public class ImageUtil {

    public static String imageToBase64(String filePath) throws Exception{
        if(StringUtils.isBlank(filePath)){
            return null;
        }
        String encode="";
        try{
            byte[] bytes = Files.readAllBytes(Paths.get(filePath));
//            encode = Base64.encode(bytes);
            encode = Base64.encodeBase64String(bytes);
        }catch (Exception e){
            throw e;
        }
        return encode;
    }

}
